window.onload=function(){
    //无缝滚动
    var oBox=document.getElementById('part-one');
    var  oUl=oBox.getElementsByTagName('ul')[0];
    var  aLi=oUl.getElementsByTagName('li');

     var time=null;
     var speed=-2;
    oUl.innerHTML=oUl.innerHTML+oUl.innerHTML;

    oUl.style.width=aLi[0].offsetWidth*aLi.length+'px';

    function move(){
        if(oUl.offsetLeft<-oUl.offsetWidth/2){
            oUl.style.left='0';
        }
         if(oUl.offsetLeft>0){
            oUl.style.left= -oUl.offsetWidth/2 +'px';
        }
        oUl.style.left=oUl.offsetLeft+speed+'px';
    }
    time=setInterval(move,30);

    oBox.onmouseover=function(){
        clearInterval(time);
    }
    oBox.onmouseout=function(){
        time=setInterval(move,30);
    }
    //新闻轮播图
    var mySwiper = new Swiper('.swiper-container', {
        autoplay:true,
        pagination: {
            el: '.swiper-pagination',
            clickable: true,
            renderBullet: function (index, className) {
              return '<span class="' + className + '">' + '</span>';
            },
          },
    });

    // 视频显示
    var  oBtn=document.getElementById('btn');
    var  oVideo=document.getElementById('video');

   
    oBtn.onclick=function(){
        oVideo.style.height=document.body.offsetHeight+'px';
      
        oVideo.style.display='block';
    };
    var oClose=document.getElementById('close');
    var oVideoa=oVideo.getElementsByTagName('video');   //获取视频video
   
    oClose.onclick=function(){

        oVideo.style.display='none';
        for(var i=0;i<oVideoa.length;i++){
            oVideoa[i].pause();
        }
        
    };

  



   
    //定时器
   //时间的跳动
    var oNum1=document.getElementById('num1');
    var oSpan1=oNum1.getElementsByTagName('span')[0];
    var oNum2=document.getElementById('num2');
    var oSpan2=oNum2.getElementsByTagName('span')[0];
    var oNum3=document.getElementById('num3');
    var oSpan3=oNum3.getElementsByTagName('span')[0];
    var timer=null;
    function timers(el,tar,time) {
        timer = setInterval(function(){
            var speeds =  (tar-parseInt(el.innerHTML)) / 10;

            speeds=speeds>0 ? Math.ceil(speeds) : Math.floor(speeds);
            if(parseInt(el) >= tar){
                clearInterval(timer);
            }else {
                el.innerHTML=parseInt(parseInt(el.innerHTML)+speeds);
                console.log(el);
            }
        },time);
    }
    timers(oSpan1,3242,20);
    timers(oSpan2,417492,11);
    timers(oSpan3,42268,12);


    //AJAX
    var xhr = new XMLHttpRequest();
    xhr.open('get','http://jsonplaceholder.typicode.com/posts',true);
    xhr.send();
    xhr.onreadystatechange=function(){
         if (this.status == 200 && this.readyState == 4) {
             var jsonuser = JSON.parse(this.responseText).slice(0,10);
          
             console.log(jsonuser.slice(0,10));

             var output = '';

             for (var i in jsonuser) {
                 output += '<li><a href="header.html?id='+jsonuser[i].id+'">'+jsonuser[i].title+'</a></li>';
                 document.getElementById('users').innerHTML = output;
             }

         }
         else if(this.status == 404){
          document.getElementById('users').innerHTML = "NOT Found 404";
         }
    };
    var oImga=this.document.getElementById('img-a');
    var oA=oImga.getElementsByClassName('a');


    

    



    

   
}